<template>
  <div>
    <div class="select-time">
      <a-select style="width: 150px" v-model="days" @change="changeDay">
        <a-select-option :value="1"> 近七天 </a-select-option>
        <a-select-option :value="2"> 近30天 </a-select-option>
      </a-select>
    </div>
    <div class="analyze-chart">
      <ve-line :data="chartData" :settings="chartSettings"></ve-line>
    </div>
  </div>
</template>

<script>
import { trendAnalysisData } from '@/api/customForm'
export default {
  props:{
      id:Number
  },
  data() {
      this.chartSettings = {
        yAxisName: ['单位：个']
      }
    return {
      days: 1,
      chartData: {
        columns: ['日期', '浏览量', '提交量'],
        rows: [
          
        ],
      },
    }
  },
  created(){
      this.getData()
  },
  methods: {
    getData() {
      trendAnalysisData(this.id,{ time_type: this.days })
        .then((res) => {
            let arr=JSON.parse(JSON.stringify(res))
            let arr1=[]
            for(let key in arr){
                arr1.push({
                    '日期':key,
                    '浏览量':arr[key].look_num,
                    '提交量':arr[key].submit_num
                })
            }
            this.chartData.rows=arr1
        })
        .catch((err) => {
          this.$message.error(err.data.message || '获取失败')
        })
    },
    changeDay(){
        this.getData()
    },
  },
}
</script>

<style lang="less" scoped>
.select-time {
  margin-left: 16px;
  margin-bottom: 39px;
}
.analyze-chart {
  margin-top: 39px;
  height: 372px;
}
</style>